package com.tofindaway.entity;

import java.util.Arrays;
import java.util.Date;
import java.util.Set;

public class Article {
	private Long id;
	private String title;
	private String summary;
	private String content;
	private Long isDel;
	private Date created;
	private Date deleted;
	private Date lastUpdated;
	private Set<Reply> replaySet;
	private User user;
	private String tag;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Long getIsDel() {
		return isDel;
	}

	public void setIsDel(Long isDel) {
		this.isDel = isDel;
	}

	public Date getCreated() {
		if (created == null) {
			created = new Date();
		}
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public Date getDeleted() {
		return deleted;
	}

	public void setDeleted(Date deleted) {
		this.deleted = deleted;
	}

	public Date getLastUpdated() {
		return lastUpdated;
	}

	public void setLastUpdated(Date lastUpdated) {
		this.lastUpdated = lastUpdated;
	}

	public Set<Reply> getReplaySet() {
		return replaySet;
	}

	public void setReplaySet(Set<Reply> replaySet) {
		this.replaySet = replaySet;
	}

	public String[] getTags() {
		return getTag() != null ? getTag().replace(" ", "").split(",") : null;
	}

	public void setTags(String[] tags) {
		this.tag = Arrays.toString(tags).replaceAll("\\]|\\[", "");
	}

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Article other = (Article) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Article [id=" + id + ", title=" + title + ", summary="
				+ summary + ", isDel=" + isDel + ", created=" + created
				+ ", deleted=" + deleted + ", lastUpdated=" + lastUpdated
				+ ", tags=" + tag + "]";
	}

}
